var common = require("../../../public.js");
Page({
  data: {
    pageNum: 1,
    pageSize: 10,
    storeList: [],
    imageUrl:[],
    type: '',
    isLoadingBusy: false,
    noMoreData: false,
    city: '',
    lon: 0,
    lat: 0,
    refreshing: false,
    lun:true,
   
  },
    // 开始播放
    begain(e){
      this.setData({
        lun:false
      })
     },
     // 播放完毕
     ended(e){
       this.setData({
         lun:true
       })
     },
  onLoad: function (options) {
    console.log(options,"11111")
 
    const that = this
    const id = options.id
    that.setData({
      id,
      type: options.type
    },()=>{
      that.getTopImage()
    })
    const name = options.name
    if (name) {
      wx.setNavigationBarTitle({
        title: name,
      })
    }

    getApp().getLocation(function (data) {
      that.data.lon = data.longitude
      that.data.lat = data.latitude
      console.log(data)
      that.data.city = data.regeocodeData.addressComponent.city
      that.setData({
        refreshing: true
      })
      // wx.startPullDownRefresh()
      that.getScenicAreaList(true)
    }, function () {
      that.setData({
        refreshing: true
      })
      // wx.startPullDownRefresh()
      that.getScenicAreaList(true)
    })
  },

  // 获取上方的图片
  getTopImage(){
    var that = this
    common.get('/advertisements/storeListTopAds', {storeType:that.data.id}, res => {
      if (res.status === 200) {
         this.setData({
          imageUrl: res.data
         })
      } else {
        common.showRequestErrMsg(res)
      }
  })
  },
  getScenicAreaList(refresh = false) { // 获取景点列表
    const that = this
    if (refresh) {
      that.setData({
        noMoreData: false
      })
    }
    if (that.data.noMoreData || that.data.isLoadingBusy) {
      return
    }
    if (refresh) {
      that.setData({
        refreshing: true
      })
    } else {
      this.setData({
        isLoadingBusy: true
      })
    }
    const pageNum = refresh ? 1 : this.data.pageNum + 1
    let tempJson = {
      storeTypeId: that.data.id,
      cityName: that.data.city,
      pageNum,
      pageSize: that.data.pageSize,
      xpoint: that.data.lon,
      ypoint: that.data.lat,
      distance: '',
      recentIncome: '',
      commentRate: '',
    }
    common.post('/store/getSearchStoreListByStoreTypeId', tempJson, function (res) {
      if (res.status === 200) {
        that.data.pageNum = pageNum
        if (res.data != '') {
          const list = refresh ? res.data : [...that.data.storeList, ...res.data]
          that.setData({
            storeList: list
          })
        } else {
          that.setData({
            noMoreData: true
          })
        }
      }
    }, function () {
      that.setData({
        isLoadingBusy: false,
        refreshing: false
      })
      if (refresh) {
        //停止下拉刷新
        wx.stopPullDownRefresh()
      }
    })
  },
  toScenicArea(e) {
    let {
      item
    } = e.currentTarget.dataset


    this.shopInfo(item);
 
 
  },


    /**
   * 跳转到店铺详情页
   * @param {object} e 参数对象
   */
     // 判断模板 industryType   行业类型  1通用行业 2餐饮行业  3家电行业
     shopInfo(item) {
        var that = this
        var tempJson = {
            storeId: item.id,
            // storeId:33,
            xpoint: this.data.lat,
            ypoint: this.data.lon,
            xcFlag: '0' //是否含有携程门票 0不含有
        }
        common.get('/store/mainPageInfo', tempJson, res => {
            that.setData({
                industryType: res.data.store.industryType
            }, () => {
              if (this.data.industryType == 1) {
                  const idx = item.storeId ? item.storeId : item.id // 兼容不同页面...
                  const storeName = item.storeName ? item.storeName : item.name // 兼容不同页面...
                  const storeImage = item.storeImage ? item.storeImage : ''
                  var param = '';
  
                  wx.navigateTo({
                      url: '/packageA/pages/Goods/storePage/index?id=' + idx +
                          '&storeName=' + storeName +
                          '&storeImage=' + storeImage + param
                  })
              }else if (this.data.industryType == 2) {
               
                    wx.navigateTo({
                        url: `/packageC/pages/activeBei/activeBei?id=${item.id}&name=${item.storeName}`,
                    })
               
                  
                }else if(this.data.industryType == 4){// 景区
  
                  const idx = item.storeId ? item.storeId : item.id // 兼容不同页面...
                  const storeTypeName = '景区景点';
                  var type = 1;
                  var storeType;
                  wx.navigateTo({
                      url: '/pages/ScenicArea/ScenicAreaMainPage/index?id=' + idx + '&moduleType=' + type +
                          '&storeTypeName=' + storeTypeName + '&storeType=' + storeType,
                  })
  
                }else if(this.data.industryType == 5){// 场馆
                      const idx = item.storeId ? item.storeId : item.id // 兼容不同页面...
                      const storeTypeName = '文体场馆';
                      var type = 2;
                      var storeType;
                      wx.navigateTo({
                          url: '/pages/ScenicArea/ScenicAreaMainPage/index?id=' + idx + '&moduleType=' + type +
                              '&storeTypeName=' + storeTypeName + '&storeType=' + storeType,
                      })
                }

            //   common.gotoStore(item,'',this.data.type) //页面跳转
             
            })
           
        })
    },


    
  onShow(){
    this.setData({
      stopmuic:false,
     
    })
  },
  onReachBottom: function () {
    this.getScenicAreaList(false)
  },

  onPullDownRefresh: function () {
    this.getScenicAreaList(true)
  },
  onShareAppMessage: function () {
    return {
      title: '飞羊精选',
      path: 'pages/ScenicArea/ScenicAreaList/index?id=' + this.data.id + '&type=' + this.data.type,
      imageUrl: 'https://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/xfj/share.jpg',
      success: (res) => { },
      fail: (res) => {
        // 分享失败
      }
    }
  },
  onShareTimeline(){
    return {
      title: '飞羊精选',
      query:'id=' + this.data.id + '&type=' + this.data.type,
    
      imageUrl: 'https://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/xfj/share.jpg',
      success: (res) => { },
      fail: (res) => {
        // 分享失败
      }
    }
  }
})